﻿//-----------------------------------------------------------------------
// <copyright file="UpdateRelease.Data.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Data;
using GateShift.Common.Repository;
using GateShift.Common.Repository.Interfaces.DataInterfaces.UpdateData;

#endregion

namespace GateShift.Servers.WCFHost.UpdateData.Entities
{
    /// <summary>
    /// Data class for UpdateRelease Data
    /// </summary>
    public partial class UpdateRelease : IUpdateReleaseData
    {
        #region State Management

        /// <summary>
        /// Gets a value indicating whether or not this instance has been modified
        /// </summary>
        public bool IsDirty
        {
            get
            {
                if (IsNew)
                {
                    return true;
                }

                return EntityState == EntityState.Modified;
            }
        }

        /// <summary>
        /// Gets a value indicating whether or not this instance is new
        /// </summary>
        public bool IsNew
        {
            get
            {
                // Before it is attached if the key is null then we are new
                if (EntityState == EntityState.Detached)
                {
                    if (EntityKey == null)
                    {
                        return true;
                    }
                }

                return EntityState == EntityState.Added;
            }
        }

        /// <summary>
        /// Gets a value indicating whether or not this instance has been deleted
        /// </summary>
        public bool IsDeleted
        {
            get
            {
                return EntityState == EntityState.Deleted;
            }
        }

        #endregion

        #region Identity Management

        /// <summary>
        /// Gets an Identity based reference for this item
        /// </summary>
        public Identity ID
        {
            get
            {
                return new Identity(ReleaseID);
            }
        }

        #endregion

        #region IUpdateReleaseData Members

        /// <summary>
        /// Gets or sets the version for the release
        /// </summary>
        Version IUpdateReleaseData.Version
        {
            get
            {
                return new Version(Version);
            }

            set
            {
                if (Version == null)
                {
                    throw new ArgumentNullException("value", "Version must have a value");
                }

                Version = value.ToString();
            }
        }

        #endregion

        #region Validation

        /// <summary>
        /// Handles validating of Name being changed
        /// </summary>
        /// <param name="value">Value to validate</param>
        partial void OnNameChanging(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new NullReferenceException("Name cannot be null or empty");
            }

            if (value.Length > 50)
            {
                throw new IndexOutOfRangeException("Name cannot exceed 50 characters");
            }
        }

        /// <summary>
        /// Handles validating of Description being changed
        /// </summary>
        /// <param name="value">Value to validate</param>
        partial void OnDescriptionChanging(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new NullReferenceException("Description cannot be null or empty");
            }

            if (value.Length > 8000)
            {
                throw new IndexOutOfRangeException("Description cannot exceed 8000 characters");
            }
        }

        #endregion
    }
}